// perl_dl.c - use dynamically loaded perl

#include "perl_dl.h"

int alert(char* msg) {
	return MessageBox(NULL, msg, "PlPN", MB_OK);
}

HMODULE perl_module;

/*

Magic formula:

1) Declare these extern "C" in plugin.h
2) Do not include plugin.h here
3) Declare them (not extern) here

Why does it work?
I am almost entirely self-taught, so it may represent a fundamental
misunderstanding on my part about the nature of "extern"

Or maybe it has something to do with the fact that these
are dynamically loaded functions

*/

perlfunc_sys_init3 my_Perl_sys_init3;
perlfunc_sys_term my_Perl_sys_term;
perlfunc_alloc my_perl_alloc;
perlfunc_construct my_perl_construct;
perlfunc_destruct my_perl_destruct;
perlfunc_free my_perl_free;
perlfunc_parse my_perl_parse;
perlfunc_run my_perl_run;
perlfunc_Perl_Ierrgv_ptr my_Perl_Ierrgv_ptr;
perlfunc_Perl_call_argv my_Perl_call_argv;
perlfunc_Perl_eval_pv my_Perl_eval_pv;
perlfunc_Perl_gv_add_by_type my_Perl_gv_add_by_type;
perlfunc_Perl_sv_2bool my_Perl_sv_2bool;
perlfunc_Perl_sv_2pv_flags my_Perl_sv_2pv_flags;

#ifdef NEED_XS

perlfunc_Perl_av_fetch my_Perl_av_fetch;
perlfunc_Perl_av_len my_Perl_av_len;
perlfunc_Perl_av_store my_Perl_av_store;
perlfunc_Perl_call_list my_Perl_call_list;
perlfunc_Perl_call_method my_Perl_call_method;
perlfunc_Perl_call_pv my_Perl_call_pv;
perlfunc_Perl_call_sv my_Perl_call_sv;
perlfunc_Perl_croak_nocontext my_Perl_croak_nocontext;
perlfunc_Perl_croak_xs_usage my_Perl_croak_xs_usage;
perlfunc_Perl_free_tmps my_Perl_free_tmps;
perlfunc_Perl_get_context my_Perl_get_context;
perlfunc_Perl_get_hv my_Perl_get_hv;
perlfunc_Perl_get_sv my_Perl_get_sv;
perlfunc_Perl_gv_stashpv my_Perl_gv_stashpv;
perlfunc_Perl_hv_common_key_len my_Perl_hv_common_key_len;
perlfunc_Perl_Iamagic_generation_ptr my_Perl_Iamagic_generation_ptr;
perlfunc_Perl_Icurpad_ptr my_Perl_Icurpad_ptr;
perlfunc_Perl_Idirty_ptr my_Perl_Idirty_ptr;
perlfunc_Perl_Imarkstack_max_ptr my_Perl_Imarkstack_max_ptr;
perlfunc_Perl_Imarkstack_ptr_ptr my_Perl_Imarkstack_ptr_ptr;
perlfunc_Perl_Iop_ptr my_Perl_Iop_ptr;
perlfunc_Perl_Iscopestack_ix_ptr my_Perl_Iscopestack_ix_ptr;
perlfunc_Perl_Istack_base_ptr my_Perl_Istack_base_ptr;
perlfunc_Perl_Istack_sp_ptr my_Perl_Istack_sp_ptr;
perlfunc_Perl_Istack_max_ptr my_Perl_Istack_max_ptr;
perlfunc_Perl_Isv_no_ptr my_Perl_Isv_no_ptr;
perlfunc_Perl_ISv_ptr my_Perl_ISv_ptr;
perlfunc_Perl_Isv_yes_ptr my_Perl_Isv_yes_ptr;
perlfunc_Perl_Isv_undef_ptr my_Perl_Isv_undef_ptr;
perlfunc_Perl_Itmps_floor_ptr my_Perl_Itmps_floor_ptr;
perlfunc_Perl_Itmps_ix_ptr my_Perl_Itmps_ix_ptr;
perlfunc_Perl_IXpv_ptr my_Perl_IXpv_ptr;
perlfunc_Perl_Iunitcheckav_ptr my_Perl_Iunitcheckav_ptr;
perlfunc_Perl_markstack_grow my_Perl_markstack_grow;
perlfunc_Perl_mg_set my_Perl_mg_set;
perlfunc_Perl_newRV my_Perl_newRV;
perlfunc_Perl_newRV_noinc my_Perl_newRV_noinc;
perlfunc_Perl_newSV my_Perl_newSV;
perlfunc_Perl_newSViv my_Perl_newSViv;
perlfunc_Perl_newSVpv my_Perl_newSVpv;
perlfunc_Perl_newSVpvn my_Perl_newSVpvn;
perlfunc_Perl_newSVsv my_Perl_newSVsv;
perlfunc_Perl_newSVuv my_Perl_newSVuv;
perlfunc_Perl_newXS my_Perl_newXS;
perlfunc_Perl_newXS_flags my_Perl_newXS_flags;
perlfunc_Perl_newSV_type my_Perl_newSV_type;
perlfunc_Perl_pop_scope my_Perl_pop_scope;
perlfunc_Perl_push_scope my_Perl_push_scope;
perlfunc_Perl_save_int my_Perl_save_int;
perlfunc_Perl_stack_grow my_Perl_stack_grow;
perlfunc_Perl_sv_2iv_flags my_Perl_sv_2iv_flags;
perlfunc_Perl_sv_2mortal my_Perl_sv_2mortal;
perlfunc_Perl_sv_2uv_flags my_Perl_sv_2uv_flags;
perlfunc_Perl_sv_bless my_Perl_sv_bless;
perlfunc_Perl_sv_catpvn_flags my_Perl_sv_catpvn_flags;
perlfunc_Perl_sv_derived_from my_Perl_sv_derived_from;
perlfunc_Perl_sv_free my_Perl_sv_free;
perlfunc_Perl_sv_isobject my_Perl_sv_isobject;
perlfunc_Perl_sv_len my_Perl_sv_len;
perlfunc_Perl_sv_mortalcopy my_Perl_sv_mortalcopy;
perlfunc_Perl_sv_newmortal my_Perl_sv_newmortal;
perlfunc_Perl_sv_setiv my_Perl_sv_setiv;
perlfunc_Perl_sv_setpv my_Perl_sv_setpv;
perlfunc_Perl_sv_setref_pv my_Perl_sv_setref_pv;
perlfunc_Perl_sv_setsv_flags my_Perl_sv_setsv_flags;
perlfunc_Perl_sv_setuv my_Perl_sv_setuv;
perlfunc_Perl_uvuni_to_utf8_flags my_Perl_uvuni_to_utf8_flags;
perlfunc_Perl_warn_nocontext my_Perl_warn_nocontext;

perlfunc_bootstrap my_boot_DynaLoader;
perlfunc_bootstrap my_boot_Win32CORE;

#endif

BOOL load_perl(LPCTSTR filename, int* count) {
	// count will be -1 if library fails to load
	// otherwise it will be the number of functions successfully loaded
	*count = -1;
	perl_module = LoadLibrary(filename);
	if (perl_module == NULL)
		return FALSE;

	count++;
	my_Perl_sys_init3 = (perlfunc_sys_init3)GetProcAddress(perl_module, "Perl_sys_init3");
	if (my_Perl_sys_init3 == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sys_term = (perlfunc_sys_term)GetProcAddress(perl_module, "Perl_sys_term");
	if (my_Perl_sys_term == NULL)
		return FALSE;
	
	*count++;
	my_perl_alloc = (perlfunc_alloc)GetProcAddress(perl_module, "perl_alloc");
	if (my_perl_alloc == NULL)
		return FALSE;
	
	*count++;
	my_perl_construct = (perlfunc_construct)GetProcAddress(perl_module, "perl_construct");
	if (my_perl_construct == NULL)
		return FALSE;
	
	*count++;
	my_perl_destruct = (perlfunc_destruct)GetProcAddress(perl_module, "perl_destruct");
	if (my_perl_destruct == NULL)
		return FALSE;
	
	*count++;
	my_perl_free = (perlfunc_free)GetProcAddress(perl_module, "perl_free");
	if (my_perl_free == NULL)
		return FALSE;
	
	*count++;
	my_perl_parse = (perlfunc_parse)GetProcAddress(perl_module, "perl_parse");
	if (my_perl_parse == NULL)
		return FALSE;
	
	*count++;
	my_perl_run = (perlfunc_run)GetProcAddress(perl_module, "perl_run");
	if (my_perl_run == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Ierrgv_ptr = (perlfunc_Perl_Ierrgv_ptr)GetProcAddress(perl_module, "Perl_Ierrgv_ptr");
	if (my_Perl_Ierrgv_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_call_argv = (perlfunc_Perl_call_argv)GetProcAddress(perl_module, "Perl_call_argv");
	if (my_Perl_call_argv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_eval_pv = (perlfunc_Perl_eval_pv)GetProcAddress(perl_module, "Perl_eval_pv");
	if (my_Perl_eval_pv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_gv_add_by_type = (perlfunc_Perl_gv_add_by_type)GetProcAddress(perl_module, "Perl_gv_add_by_type");
	if (my_Perl_gv_add_by_type == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_2bool = (perlfunc_Perl_sv_2bool)GetProcAddress(perl_module, "Perl_sv_2bool");
	if (my_Perl_sv_2bool == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_2pv_flags = (perlfunc_Perl_sv_2pv_flags)GetProcAddress(perl_module, "Perl_sv_2pv_flags");
	if (my_Perl_sv_2pv_flags == NULL)
		return FALSE;

#ifdef NEED_XS

	*count++;
	my_Perl_av_fetch = (perlfunc_Perl_av_fetch)GetProcAddress(perl_module, "Perl_av_fetch");
	if (my_Perl_av_fetch == NULL)
		return FALSE;

	*count++;
	my_Perl_av_len = (perlfunc_Perl_av_len)GetProcAddress(perl_module, "Perl_av_len");
	if (my_Perl_av_len == NULL)
		return FALSE;
	
	*count++;
	my_Perl_av_store = (perlfunc_Perl_av_store)GetProcAddress(perl_module, "Perl_av_store");
	if (my_Perl_av_store == NULL)
		return FALSE;

	*count++;
	my_Perl_call_list = (perlfunc_Perl_call_list)GetProcAddress(perl_module, "Perl_call_list");
	if (my_Perl_call_list == NULL)
		return FALSE;

	*count++;
	my_Perl_call_method = (perlfunc_Perl_call_method)GetProcAddress(perl_module, "Perl_call_method");
	if (my_Perl_call_method == NULL)
		return FALSE;

	*count++;
	my_Perl_call_pv = (perlfunc_Perl_call_pv)GetProcAddress(perl_module, "Perl_call_pv");
	if (my_Perl_call_pv == NULL)
		return FALSE;

	*count++;
	my_Perl_call_sv = (perlfunc_Perl_call_sv)GetProcAddress(perl_module, "Perl_call_sv");
	if (my_Perl_call_sv == NULL)
		return FALSE;

	*count++;
	my_Perl_croak_nocontext = (perlfunc_Perl_croak_nocontext)GetProcAddress(perl_module, "Perl_croak_nocontext");
	if (my_Perl_croak_nocontext == NULL)
		return FALSE;
	
	*count++;
	my_Perl_croak_xs_usage = (perlfunc_Perl_croak_xs_usage)GetProcAddress(perl_module, "Perl_croak_xs_usage");
	if (my_Perl_croak_xs_usage == NULL)
		return FALSE;

	*count++;
	my_Perl_free_tmps = (perlfunc_Perl_free_tmps)GetProcAddress(perl_module, "Perl_free_tmps");
	if (my_Perl_free_tmps == NULL)
		return FALSE;
	
	*count++;
	my_Perl_get_context = (perlfunc_Perl_get_context)GetProcAddress(perl_module, "Perl_get_context");
	if (my_Perl_get_context == NULL)
		return FALSE;

	*count++;
	my_Perl_get_hv = (perlfunc_Perl_get_hv)GetProcAddress(perl_module, "Perl_get_hv");
	if (my_Perl_get_hv == NULL)
		return FALSE;

	*count++;
	my_Perl_get_sv = (perlfunc_Perl_get_sv)GetProcAddress(perl_module, "Perl_get_sv");
	if (my_Perl_get_sv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_gv_stashpv = (perlfunc_Perl_gv_stashpv)GetProcAddress(perl_module, "Perl_gv_stashpv");
	if (my_Perl_gv_stashpv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_hv_common_key_len = (perlfunc_Perl_hv_common_key_len)GetProcAddress(perl_module, "Perl_hv_common_key_len");
	if (my_Perl_hv_common_key_len == NULL)
		return FALSE;
		
	*count++;
	my_Perl_Iamagic_generation_ptr = (perlfunc_Perl_Iamagic_generation_ptr)GetProcAddress(perl_module, "Perl_Iamagic_generation_ptr");
	if (my_Perl_Iamagic_generation_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Icurpad_ptr = (perlfunc_Perl_Icurpad_ptr)GetProcAddress(perl_module, "Perl_Icurpad_ptr");
	if (my_Perl_Icurpad_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_Idirty_ptr = (perlfunc_Perl_Idirty_ptr)GetProcAddress(perl_module, "Perl_Idirty_ptr");
	if (my_Perl_Idirty_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_Imarkstack_max_ptr = (perlfunc_Perl_Imarkstack_max_ptr)GetProcAddress(perl_module, "Perl_Imarkstack_max_ptr");
	if (my_Perl_Imarkstack_max_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Imarkstack_ptr_ptr = (perlfunc_Perl_Imarkstack_ptr_ptr)GetProcAddress(perl_module, "Perl_Imarkstack_ptr_ptr");
	if (my_Perl_Imarkstack_ptr_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Iop_ptr = (perlfunc_Perl_Iop_ptr)GetProcAddress(perl_module, "Perl_Iop_ptr");
	if (my_Perl_Iop_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Iscopestack_ix_ptr = (perlfunc_Perl_Iscopestack_ix_ptr)GetProcAddress(perl_module, "Perl_Iscopestack_ix_ptr");
	if (my_Perl_Iscopestack_ix_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Istack_base_ptr = (perlfunc_Perl_Istack_base_ptr)GetProcAddress(perl_module, "Perl_Istack_base_ptr");
	if (my_Perl_Istack_base_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_Istack_max_ptr = (perlfunc_Perl_Istack_max_ptr)GetProcAddress(perl_module, "Perl_Istack_max_ptr");
	if (my_Perl_Istack_max_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Istack_sp_ptr = (perlfunc_Perl_Istack_sp_ptr)GetProcAddress(perl_module, "Perl_Istack_sp_ptr");
	if (my_Perl_Istack_sp_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_ISv_ptr = (perlfunc_Perl_ISv_ptr)GetProcAddress(perl_module, "Perl_ISv_ptr");
	if (my_Perl_ISv_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Isv_no_ptr = (perlfunc_Perl_Isv_no_ptr)GetProcAddress(perl_module, "Perl_Isv_no_ptr");
	if (my_Perl_Isv_no_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Isv_undef_ptr = (perlfunc_Perl_Isv_undef_ptr)GetProcAddress(perl_module, "Perl_Isv_undef_ptr");
	if (my_Perl_Isv_undef_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Isv_yes_ptr = (perlfunc_Perl_Isv_yes_ptr)GetProcAddress(perl_module, "Perl_Isv_yes_ptr");
	if (my_Perl_Isv_yes_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_Itmps_floor_ptr = (perlfunc_Perl_Itmps_floor_ptr)GetProcAddress(perl_module, "Perl_Itmps_floor_ptr");
	if (my_Perl_Itmps_floor_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_Itmps_ix_ptr = (perlfunc_Perl_Itmps_ix_ptr)GetProcAddress(perl_module, "Perl_Itmps_ix_ptr");
	if (my_Perl_Itmps_ix_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_IXpv_ptr = (perlfunc_Perl_IXpv_ptr)GetProcAddress(perl_module, "Perl_IXpv_ptr");
	if (my_Perl_IXpv_ptr == NULL)
		return FALSE;
	
	*count++;
	my_Perl_Iunitcheckav_ptr = (perlfunc_Perl_Iunitcheckav_ptr)GetProcAddress(perl_module, "Perl_Iunitcheckav_ptr");
	if (my_Perl_Iunitcheckav_ptr == NULL)
		return FALSE;

	*count++;
	my_Perl_markstack_grow = (perlfunc_Perl_markstack_grow)GetProcAddress(perl_module, "Perl_markstack_grow");
	if (my_Perl_markstack_grow == NULL)
		return FALSE;
	
	*count++;
	my_Perl_mg_set = (perlfunc_Perl_mg_set)GetProcAddress(perl_module, "Perl_mg_set");
	if (my_Perl_mg_set == NULL)
		return FALSE;

	*count++;
	my_Perl_newRV = (perlfunc_Perl_newRV)GetProcAddress(perl_module, "Perl_newRV");
	if (my_Perl_newRV == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newRV_noinc = (perlfunc_Perl_newRV_noinc)GetProcAddress(perl_module, "Perl_newRV_noinc");
	if (my_Perl_newRV_noinc == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSV = (perlfunc_Perl_newSV)GetProcAddress(perl_module, "Perl_newSV");
	if (my_Perl_newSV == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSViv = (perlfunc_Perl_newSViv)GetProcAddress(perl_module, "Perl_newSViv");
	if (my_Perl_newSViv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSVpv = (perlfunc_Perl_newSVpv)GetProcAddress(perl_module, "Perl_newSVpv");
	if (my_Perl_newSVpv == NULL)
		return FALSE;

	*count++;
	my_Perl_newSVpvn = (perlfunc_Perl_newSVpvn)GetProcAddress(perl_module, "Perl_newSVpvn");
	if (my_Perl_newSVpvn == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSVsv = (perlfunc_Perl_newSVsv)GetProcAddress(perl_module, "Perl_newSVsv");
	if (my_Perl_newSVsv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSVuv = (perlfunc_Perl_newSVuv)GetProcAddress(perl_module, "Perl_newSVuv");
	if (my_Perl_newSVuv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newSV_type = (perlfunc_Perl_newSV_type)GetProcAddress(perl_module, "Perl_newSV_type");
	if (my_Perl_newSV_type == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newXS = (perlfunc_Perl_newXS)GetProcAddress(perl_module, "Perl_newXS");
	if (my_Perl_newXS == NULL)
		return FALSE;
	
	*count++;
	my_Perl_newXS_flags = (perlfunc_Perl_newXS_flags)GetProcAddress(perl_module, "Perl_newXS_flags");
	if (my_Perl_newXS_flags == NULL)
		return FALSE;

	*count++;
	my_Perl_pop_scope = (perlfunc_Perl_pop_scope)GetProcAddress(perl_module, "Perl_pop_scope");
	if (my_Perl_pop_scope == NULL)
		return FALSE;

	*count++;
	my_Perl_push_scope = (perlfunc_Perl_push_scope)GetProcAddress(perl_module, "Perl_push_scope");
	if (my_Perl_push_scope == NULL)
		return FALSE;

	*count++;
	my_Perl_save_int = (perlfunc_Perl_save_int)GetProcAddress(perl_module, "Perl_save_int");
	if (my_Perl_save_int == NULL)
		return FALSE;

	*count++;
	my_Perl_stack_grow = (perlfunc_Perl_stack_grow)GetProcAddress(perl_module, "Perl_stack_grow");
	if (my_Perl_stack_grow == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_2iv_flags = (perlfunc_Perl_sv_2iv_flags)GetProcAddress(perl_module, "Perl_sv_2iv_flags");
	if (my_Perl_sv_2iv_flags == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_2mortal = (perlfunc_Perl_sv_2mortal)GetProcAddress(perl_module, "Perl_sv_2mortal");
	if (my_Perl_sv_2mortal == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_2uv_flags = (perlfunc_Perl_sv_2uv_flags)GetProcAddress(perl_module, "Perl_sv_2uv_flags");
	if (my_Perl_sv_2uv_flags == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_bless = (perlfunc_Perl_sv_bless)GetProcAddress(perl_module, "Perl_sv_bless");
	if (my_Perl_sv_bless == NULL)
		return FALSE;

	*count++;
	my_Perl_sv_catpvn_flags = (perlfunc_Perl_sv_catpvn_flags)GetProcAddress(perl_module, "Perl_sv_catpvn_flags");
	if (my_Perl_sv_catpvn_flags == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_derived_from = (perlfunc_Perl_sv_derived_from)GetProcAddress(perl_module, "Perl_sv_derived_from");
	if (my_Perl_sv_derived_from == NULL)
		return FALSE;

	*count++;
	my_Perl_sv_free = (perlfunc_Perl_sv_free)GetProcAddress(perl_module, "Perl_sv_free");
	if (my_Perl_sv_free == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_isobject = (perlfunc_Perl_sv_isobject)GetProcAddress(perl_module, "Perl_sv_isobject");
	if (my_Perl_sv_isobject == NULL)
		return FALSE;

	*count++;
	my_Perl_sv_len = (perlfunc_Perl_sv_len)GetProcAddress(perl_module, "Perl_sv_len");
	if (my_Perl_sv_len == NULL)
		return FALSE;

	*count++;
	my_Perl_sv_mortalcopy = (perlfunc_Perl_sv_mortalcopy)GetProcAddress(perl_module, "Perl_sv_mortalcopy");
	if (my_Perl_sv_mortalcopy == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_newmortal = (perlfunc_Perl_sv_newmortal)GetProcAddress(perl_module, "Perl_sv_newmortal");
	if (my_Perl_sv_newmortal == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_setiv = (perlfunc_Perl_sv_setiv)GetProcAddress(perl_module, "Perl_sv_setiv");
	if (my_Perl_sv_setiv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_setpv = (perlfunc_Perl_sv_setpv)GetProcAddress(perl_module, "Perl_sv_setpv");
	if (my_Perl_sv_setpv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_setref_pv = (perlfunc_Perl_sv_setref_pv)GetProcAddress(perl_module, "Perl_sv_setref_pv");
	if (my_Perl_sv_setref_pv == NULL)
		return FALSE;

	*count++;
	my_Perl_sv_setsv_flags = (perlfunc_Perl_sv_setsv_flags)GetProcAddress(perl_module, "Perl_sv_setsv_flags");
	if (my_Perl_sv_setsv_flags == NULL)
		return FALSE;
	
	*count++;
	my_Perl_sv_setuv = (perlfunc_Perl_sv_setuv)GetProcAddress(perl_module, "Perl_sv_setuv");
	if (my_Perl_sv_setuv == NULL)
		return FALSE;
	
	*count++;
	my_Perl_uvuni_to_utf8_flags = (perlfunc_Perl_uvuni_to_utf8_flags)GetProcAddress(perl_module, "Perl_uvuni_to_utf8_flags");
	if (my_Perl_uvuni_to_utf8_flags == NULL)
		return FALSE;

	*count++;
	my_Perl_warn_nocontext = (perlfunc_Perl_warn_nocontext)GetProcAddress(perl_module, "Perl_warn_nocontext");
	if (my_Perl_warn_nocontext == NULL)
		return FALSE;
	
	*count++;
	my_boot_DynaLoader = (perlfunc_bootstrap)GetProcAddress(perl_module, "boot_DynaLoader");
	if (my_boot_DynaLoader == NULL)
		return FALSE;
	
	*count++;
	my_boot_Win32CORE = (perlfunc_bootstrap)GetProcAddress(perl_module, "boot_Win32CORE");
	if (my_boot_Win32CORE == NULL)
		return FALSE;

#endif

	return TRUE;
}

BOOL unload_perl() {
	return FreeLibrary(perl_module);
}

#ifdef NEED_XS

// reimplement these in terms of loaded functions
// required for perlxsi.c, which is required for
// enabling XS modules

void boot_DynaLoader(PerlInterpreter* pi, CV* cv) {
	my_boot_DynaLoader(pi,cv);
}

void boot_Win32CORE(PerlInterpreter* pi, CV* cv) {
	my_boot_Win32CORE(pi,cv);
}

#endif
